/**
 * @author Tobias Boehm
 *
 * 06.06.2011
 */
package org.anddev.andengine.extension.tbsengine.match.playerslot;

import org.anddev.andengine.extension.tbsengine.faction.AbsBaseFaction;
import org.anddev.andengine.extension.tbsengine.player.BasePlayer;
import org.anddev.andengine.extension.tbsengine.shared.IImageOrTextSelectableItem;
import org.anddev.andengine.extension.tbsengine.team.Team;

import android.graphics.drawable.Drawable;

/**
 * This class is the basis for the classes {@link AbsClientPlayerSlot} and
 * {@link BaseServerPlayerSlot}. It contains basic member variables and
 * provides the {@link SlotState} enumeration class. 
 * 
 * 
 * @author Tobias Boehm
 *
 * @param <FactionBaseClass> - Your implementation of {@link AbsBaseFaction}
 */
public abstract class AbsPlayerSlot<FactionBaseClass extends AbsBaseFaction> {

	public enum SlotState implements IImageOrTextSelectableItem {
		
		OPEN,
		CLOSED,
		OCCUPIED;

		@Override
		public Drawable getIcon() {
			// TODO Auto-generated method stub
			return null;
		}
	
		@Override
		public String getName() {
			
			return super.name();
		}
	};
	
	protected BasePlayer mPlayer;
	protected SlotState mPlayerSlotState;
	protected Team mTeam;
	protected FactionBaseClass mFaction;
	protected final long mSlotID;
	
	
	public AbsPlayerSlot(final long pSlotID, final BasePlayer pPlayer, final Team pTeam, final FactionBaseClass pFaction){
		
		this.mSlotID = pSlotID;
		
		this.mPlayer = pPlayer;
		
		this.mTeam = pTeam;
		
		this.mFaction = pFaction;
				
		this.mPlayerSlotState = SlotState.OCCUPIED;
	}
	
	public AbsPlayerSlot(final long pSlotID, final Team pTeam, final FactionBaseClass pFaction, final SlotState pSlotState){
		
		this.mSlotID = pSlotID;
		
		this.mTeam = pTeam;
		
		this.mFaction = pFaction;
		
		this.mPlayerSlotState = pSlotState;
	}
	
	public boolean hasPlayer(){
		
		return (this.mPlayer != null);
	}
	
	public BasePlayer getPlayer(){
		
		return this.mPlayer;
	}
	
	public void setPlayer(final BasePlayer pNewPlayer) {
		
		this.mPlayer = pNewPlayer;
		
		this.setSlotState(SlotState.OCCUPIED);
	}
	
	public SlotState getPlayerSlotState() {
		return mPlayerSlotState;
	}
	
	public abstract void setSlotState(final SlotState pNewPlayerSlotState);
	
	/**
	 * @return the mTeam
	 */
	public Team getTeam() {
		return mTeam;
	}
	
	/**
	 * @param pTeam the mTeamID to set
	 */
	public void setTeam(final Team pNewTeam) {
				
		this.mTeam = pNewTeam;
	}
	
	/**
	 * @return the mFaction
	 */
	public FactionBaseClass getFaction() {
		return mFaction;
	}
	
	/**
	 * @param mFaction the mFaction to set
	 */
	public void setFaction(final FactionBaseClass pNewFaction) {
			
		this.mFaction = pNewFaction;
	}
	
	/**
	 * @return the mSlotID
	 */
	public long getSlotID() {
		return mSlotID;
	}
	
}
